<template>
  <work-template v-model="detailForm" @submitOn="handleSubmit" @closeSelectedTag="closeSelectedTag" :butShow="bool">
    <div slot="form" v-loading="loading">
      <!--基础信息-->
      <basicsInfo v-model="detailForm" :state="isEdit"/>

      <!--出险信息-->
      <beDangerInfo v-model="detailForm" :settlementBoole="false"
                    :state="isEdit" ref="beDangerInfo"/>

      <!--主车定损-->
      <masterCarAssessment v-model="detailForm" :state="isEdit" ref="masterCarAssessment"/>

      <!--三者定损-->
      <threeAssessment v-model="detailForm" :state="isEdit" ref="threeAssessment"/>

      <!--其他费用-->
      <other v-model="detailForm" :state="isEdit"/>

      <!--出险相关信息*-->
      <beDangerMessage v-model="detailForm" :state="isEdit" ref="beDangerMessage"/>

      <!--收取加速折旧费*-->
      <accelerated v-model="detailForm" :state="isEdit" ref="accelerated"/>

      <!--用印文件-->
      <printedDocument v-model="detailForm" :state="isEdit" v-if="detailForm.settlementType === '1'"/>

      <!--理赔款支付（其他费用）-->
      <paymentClaims v-model="detailForm" :state="isEdit" v-if="detailForm.settlementType === '2'"/>
    </div>
  </work-template>

</template>

<script>
import {
  getSettlementDetails,
  getAddSettlementList,
  getAddSettlementDetails,
} from "@/api/bxlp/settlement.js";

export default {
  name: "SettlementDetails", //详情
  components: {
    basicsInfo: () => import("./components/basicsInfo.vue"), //基础信息
    beDangerInfo: () => import("./components/beDangerInfo.vue"), //出险信息
    masterCarAssessment: () => import("./components/masterCarAssessment.vue"), //主车定损
    threeAssessment: () => import("./components/threeAssessment.vue"), //三者定损
    other: () => import("./components/other.vue"), //其他费用
    beDangerMessage: () => import("./components/beDangerMessage.vue"), //出险相关信息
    accelerated: () => import("./components/accelerated.vue"), //收取加速折旧费
    printedDocument: () => import("./components/printedDocument.vue"), //用印文件
    paymentClaims: () => import("./components/paymentClaims.vue"), //理赔款支付（其他费用）
  },
  computed: {
    isEdit() {
      if (this.$route.query.type === "edit") {
        return "write";
      }
      if (this.$route.query.type === "view") {
        return "readonly";
      }
    },
    bool() {
      if (this.$route.query.type === "edit") {
        return true;
      }
      if (this.$route.query.type === "view") {
        return false;
      }
    },
  },
  watch: {},
  data() {
    return {
      loading: false,
      // 表单参数
      detailForm: {
        //基础信息
        carNo: "",
        vinNo: "",
        modelName: "",
        seriesName: "",
        brandName: "",
        propertyRightName: "",
        registerTime: "",
        customerName: "",
        syxPolicyCode: "",
        jqxPolicyCode: "",
        accidentTime: "",
        carId: 0,

        //出险信息
        settlementType: "1",
        insuredName: "",
        driverName: "",
        responsibilityType: "",
        responsibleInsuranceUnitName: "",
        accidentType: "",
        accidentLocation: "",
        humanInjury: "",
        reportingCaseTime: "",
        reportingCaseNum:'',

        //主车定损
        vehicleAssessmentPrice: "",
        persionAssessmentPrice: "",
        otherAssessmentPrice: "",
        assessmentTotalPrice: "",
        dangerMaintenanceShop: "",
        accidentPhotos: "",
        lossAssessmentOss: "",
        maintenanceShop:'',
        maintenanceShopId:'',

        //三者定损
        threeLossAssessmentDtoList: [],
        threeLossAssessmentUrl: '',

        //其他费用
        otherPrice: "",
        otherCostReason: "",
        otherCostUrl: "",

        //出险相关信息
        advancePayment: "",
        advancePaymentCost: '',
        assessmentRemark: "",

        //收取加速折旧费
        depreciationPlan: "",
        depreciationPrice: "",

        //用印文件

        //理赔款支付（其他费用）
        compensationPaymentTotalAmount: '',
        compensationPaymentDto: [
          {
            payee: "",//收款方
            payAmount: "",//   收款费用
            collectionAccount: "", //收账号
          }
        ],

        //印章信息
        attachmentUrl: ""

      },
    };
  },
  created() {
    if (this.$route.query.id) {
      this.handleDatails();
    }
    if (this.$route.query.carNo) {
      let objData = JSON.parse(this.$route.query.obj)
      this.handleAddCarNo()
      this.detailForm.jqxPolicyCode = objData.jqxPolicyCode
      this.detailForm.syxPolicyCode = objData.syxPolicyCode
      this.detailForm.accidentTime = objData.accidentTime
    }
  },
  mounted() {
  },
  methods: {
    //获取详情
    async handleDatails() {
      this.loading = true;
      try {
        const res = await getSettlementDetails(this.$route.query.id);
        if (res.code === 200) {
          this.detailForm = res.data || {}
          this.detailForm.reportingCaseNum = res.data?.reportingCaseNum || ''
        }
      } catch (e) {
        this.loading = false;
      } finally {
        this.loading = false;
      }
    },

    //通过车牌获取新增数据
    handleAddCarNo() {
      this.loading = true;
      try {
        getAddSettlementDetails(this.$route.query.carNo).then(res => {
          if (res.code === 200) {
            let val = res.data[0]
            this.detailForm.carNo = val.carNo
            this.detailForm.vinNo = val.vinNo
            this.detailForm.modelName = val.modelName
            this.detailForm.seriesName = val.seriesName
            this.detailForm.brandName = val.brandName
            this.detailForm.propertyRightName = val.propertyRightName
            this.detailForm.carId = val.carId
            this.detailForm.customerName = val.customerName
            this.detailForm.registerTime = val.registerTime
          }
        })
      } catch (e) {
      } finally {
        this.loading = false;
      }
    },

    handleSubmit() {
      let refList = [
        this.$refs.beDangerInfo.handleEffect(),
        this.$refs.masterCarAssessment.handleEffect(),
        this.$refs.threeAssessment.handleEffect(),
        this.$refs.beDangerMessage.handleEffect(),
        this.$refs.accelerated.handleEffect(),
      ];
      Promise.all(refList)
          .then(() => {
            const loading = this.$loading({
              lock: true,
              text: "保存中",
              spinner: "el-icon-loading",
              background: "rgba(0, 0, 0, 0.7)",
            });
            getAddSettlementList(this.detailForm)
                .then((res) => {
                  if (res.code === 200) {
                    this.closeSelectedTag()
                    loading.close();
                  }
                })
                .catch(() => {
                  loading.close();
                });
          })
          .catch((e) => {
          });
    },

    closeSelectedTag() {
      this.$tab.closePage().then(({ visitedViews }) => {
        this.$router.push({
          path:'/clgl/insurance/SettlementList'
        });
      });
    },
  },
};
</script>

<style scoped lang=""></style>


